#include <iostream>
#include <string>
#include "gnuplot.h"

using namespace std;

/*Para usarla crea un objeto p.e. gp y luego manda el comando completo
p.e. plot sin(x) de la siguiente manera: gp("plot sin(x)");*/

GNUplot::GNUplot() throw(string){
	gnuplotpipe=popen("gnuplot -persist","w");
	if (!gnuplotpipe) {
		throw("\nNo se encontro GNUplot en su maquina.\n");
	}
}

GNUplot::~GNUplot(){
	fprintf(gnuplotpipe,"exit\n");
	pclose(gnuplotpipe);
}

void GNUplot::operator() (const string& command){
	fprintf(gnuplotpipe,"%s\n",command.c_str());
	fflush(gnuplotpipe); //Borra el buffer para liberar memoria al cerrar.
} 
